//
//  ViewController.m
//  Grappin
//
//  Created by iMac on 12/3/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "ViewController.h"
#import "SplashScreen.h"
#import "NavigationController.h"
#import "Globals.h"
#import "HomePage.h"
#import "ViewIdentity.h"
@interface ViewController ()

@property (retain, nonatomic) SplashScreen * splashScreen;
@property (retain, nonatomic) NavigationController * navigationController;

- (void)onSplashScreenFinished:(NSNotification *)pNotification;

@end
@implementation ViewController
@synthesize splashScreen, navigationController;
@synthesize lb1;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
   // self.lb1 = [[UILabel alloc] initWithFrame:CGRectZero];
    
    //UILabel * lb2 = self.lb1;
//self.lb1 = lb2;
   // [lb2 release];
    
//    [lb2 release];
//    self.lb1.text = @"ABC";
//    NSLog(@"text : %@", lb1.text);
//    
//    NSLog(@"count 1 : %i" , lb1.retainCount);
//    NSLog(@"count 2 : %i" , lb2.retainCount);
    
    
    [[Globals instance] loadConfig];
	// Do any additional setup after loading the view, typically from a nib.
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSplashScreenFinished:) name:[SplashScreen NOTIFICATION_SPLASH_SCREEN_FINISHED] object:nil];
    
    SplashScreen * tSplashScreen =  [[SplashScreen alloc] initWithNibName:@"SplashScreen" bundle:nil];
    self.splashScreen = tSplashScreen;
    [self.view addSubview:self.splashScreen.view];
    
    [tSplashScreen release];
    
}
- (void)onSplashScreenFinished:(NSNotification *)pNotification
{
    
    //[[NSUserDefaults standardUserDefaults] removeObjectForKey:kIsLogin];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:[SplashScreen NOTIFICATION_SPLASH_SCREEN_FINISHED] object:nil];
    
    
    [self.splashScreen.view removeFromSuperview];
    self.splashScreen = nil;    
    NavigationController * tNavigationController = [[ViewIdentity instance] getInstanceOfClass:NSStringFromClass([NavigationController class])];
    
    self.navigationController   =   tNavigationController;
    self.navigationController.view.frame    =   self.view.bounds;
    [self.view addSubview:self.navigationController.view];    
}
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
   // return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    
    return NO;
}
- (void)dealloc
{
    [navigationController release];
    [super dealloc];
}
@end
